﻿using System;
using System.Collections;
using System.Collections.Generic;
using Lean.Touch;
// using TouchScript;
// using TouchScript.Pointers;
using UniRx;
using UnityEngine;

public class Test054 : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        Application.targetFrameRate = 30;
        // var clickStream = Observable.EveryUpdate().Where(_ => Input.GetMouseButtonDown(0));
        // var obser = clickStream.Buffer(clickStream.Throttle(TimeSpan.FromMilliseconds(250)));
        // obser.Where(xs => xs.Count >= 1)
        //     .Subscribe(xs => Debug.Log("检测到令牌标点数:" + xs.Count));
        
        // Observable.EveryUpdate().Where(_ => Input.GetMouseButtonDown(0)).Select(_ => Input.touches).GroupBy(i => i.Length / 3).Subscribe(group =>
        // {
        //     group.Subscribe(number =>
        //     {
        //         Debug.LogFormat("Key:{0},Number:{1}", group.Key, number);
        //         for (int i = 0; i < number.Length; i++)
        //         {
        //             Debug.Log("fingerId:"+number[i].fingerId);
        //         }
        //     });
        // });

         //TouchManager.Instance.PointersPressed += PointersPressed;
        //
        // // Observable.Interval(TimeSpan.FromSeconds(1.0f))
        // //     .Buffer(TimeSpan.FromSeconds(3.0f))
        // //     .Subscribe(_ =>{Debug.LogFormat("currentTime:{0}",DateTime.Now.Second);})
        // //     .AddTo(this);
        // TouchManager.Instance.PointersAdded += PointersAdded;
        //
        // TouchManager.Instance.PointersRemoved += PointersRemoved;
        // TouchManager.Instance.PointersReleased += PointersReleased;
        
         //LeanTouch.OnFingerDown += HandleFingerDown;
        // //LeanTouch.OnGesture += HandleGesture;
        // LeanTouch.OnFingerUp += HandleFingerUp;

        LeanTouch.OnFingerSwipe += HandleFingerSwipe;
    }

    private void HandleFingerSwipe(LeanFinger obj)
    {
        Debug.Log(obj.ToString()+"滑动");
    }

    public List<int> Inactive;
    public List<int> Expired;
    public void HandleGesture(List<LeanFinger> fingers)
    {
        Debug.Log("Gesture with " + fingers.Count + " finger(s)");
    }

    private void HandleFingerDown(LeanFinger finger)
    {
        Debug.Log("Finger " + finger.Index + " began touching the screen");
        
    }
    
    public void HandleFingerUp(LeanFinger finger)
    {
        Debug.Log("Finger " + finger.Index + " finished touching the screen");
    }
    

    // private void PointersReleased(object sender, PointerEventArgs e)
    // {
    //     foreach (Pointer pointer in (IEnumerable<Pointer>) e.Pointers)
    //     {
    //         Debug.LogErrorFormat("PointersReleased:{0}",pointer.ToString());
    //     }
    // }
    //
    // private void PointersRemoved(object sender, PointerEventArgs e)
    // {
    //     foreach (Pointer pointer in (IEnumerable<Pointer>) e.Pointers)
    //     {
    //         Debug.LogWarningFormat("PointersRemoved:{0}",pointer.ToString());
    //     }
    // }
    //
    // void PointersAdded(object sender, PointerEventArgs e)
    // {
    //     //Debug.Log("PointersAdded");
    //     foreach (Pointer pointer in (IEnumerable<Pointer>) e.Pointers)
    //     {
    //         Debug.LogFormat("PointersAdded:{0}",pointer.ToString());
    //     }
    // }
    //
    // void PointersPressed(object sender, PointerEventArgs e)
    // {
    //     Debug.Log("PointersPressed");
    //
    //     // foreach (Pointer pointer in (IEnumerable<Pointer>) e.Pointers)
    //     // {
    //     //     Debug.LogFormat("{0}",pointer.ToString());
    //     // }
    // }

    // private void Update()
    // {
    //     foreach (var touch in Input.touches)
    //     {
    //         Debug.LogFormat("{0}",touch.fingerId);
    //     }
    // }
}

public class MPoint
{
    public List<Vector2> points;
    public int ID;
}
